import request from '../utils/apiRequest'

// 分页获取库存列表
export const getInventoryList = (page, pageSize, query) => {
  return request({
    url: '/api/inventories',
    method: 'GET',
    params: {
      page,
      pageSize,
      ...query
    }
  })
}

// 获取所有库存
export const getAllInventories = () => {
  return request({
    url: '/api/inventories/all',
    method: 'GET'
  })
}

// 获取单个库存
export const getInventoryById = (id) => {
  return request({
    url: `/api/inventories/${id}`,
    method: 'GET'
  })
}

// 根据物料和仓库获取库存
export const getInventoryByMaterialAndWarehouse = (materialId, warehouseId) => {
  return request({
    url: '/api/inventories/getByMaterialAndWarehouse',
    method: 'GET',
    params: {
      materialId,
      warehouseId
    }
  })
}

// 获取库存预警
export const getInventoryAlerts = () => {
  return request({
    url: '/api/inventories/alerts',
    method: 'GET'
  })
}

// 获取库存交易记录
export const getInventoryTransactions = (inventoryId, page, pageSize) => {
  return request({
    url: `/api/inventories/${inventoryId}/transactions`,
    method: 'GET',
    params: {
      page,
      pageSize
    }
  })
}

// 创建库存
export const createInventory = (data) => {
  return request({
    url: '/api/inventories',
    method: 'POST',
    data
  })
}

// 更新库存
export const updateInventory = (id, data) => {
  return request({
    url: `/api/inventories/${id}`,
    method: 'PUT',
    data
  })
}